//
//  UserInfo.swift
//  归档
//
//  Created by 张海峰 on 2017/7/27.
//  Copyright © 2017年 张海峰. All rights reserved.
//

import UIKit
class UserInfo: NSObject ,NSCoding {
    var name : String?
    var age : String?
    var weight : String?
    override init()
    {
        //在构造函数中，如果没有明确super.init()系统会默认生成
        super.init()
    }
    //(传字典 KVC 解析）
    init(dict : [NSString :Any]) {
        super.init()
        setValuesForKeys(dict as [String : Any])
    }
    //kvc记得重写方法 防止没有声明的的属性（weight）解析错误
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
    }
    //归档
    func encode(with aCoder: NSCoder) {
        aCoder.encode(name, forKey: "name")
        aCoder.encode(age, forKey: "age")
        aCoder.encode(weight, forKey: "weight")
    }
    //解档
    required init?(coder aDecoder: NSCoder) {
        name = aDecoder.decodeObject(forKey:"name") as? String
        age = aDecoder.decodeObject(forKey:"age") as? String
        weight = aDecoder.decodeObject(forKey:"weight") as? String
    }

}
